package com.bit.example.principle.controller;

import com.bit.example.principle.model.Dog;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/dog")
@RestController
public class DogController {
    @Autowired
    ApplicationContext context;

    @Resource(name = "singleDog")
    Dog singleDog;

    @Resource(name = "prototypeDog")
    Dog prototypeDog;

    @Resource(name = "requestDog")
    Dog requestDog;

    @Resource(name = "sessionDog")
    Dog sessionDog;

    @Resource(name = "applicationDog")
    Dog applicationDog;

    @RequestMapping("/singleton")
    public String singleton(){
        Dog contextDog = context.getBean("singleDog", Dog.class);
        return "contextDog:"+ contextDog + ", resources:" +singleDog;
    }

    @RequestMapping("/prototy")
    public String prototy(){
        Dog contextDog = context.getBean("prototypeDog", Dog.class);
        return "contextDog:"+ contextDog + ", resources:" +prototypeDog;
    }

    @RequestMapping("/request")
    public String request(){
        Dog contextDog = context.getBean("requestDog", Dog.class);
        return "contextDog:"+ contextDog + ", resources:" +requestDog;
    }

    @RequestMapping("/session")
    public String session(){
        Dog contextDog = context.getBean("sessionDog", Dog.class);
        return "contextDog:"+ contextDog + ", resources:" +sessionDog;
    }

    @RequestMapping("/application")
    public String application(){
        Dog contextDog = context.getBean("applicationDog", Dog.class);
        return "contextDog:"+ contextDog + ", resources:" +applicationDog;
    }
}
